<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-date"></i> 实验室管理系统</el-breadcrumb-item>
                <el-breadcrumb-item>设备报修信息</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-tabs type="border-card">
            <el-tab-pane label="所有设备报修信息">
                <div class="handle-box">
                    <el-input v-model="select_word" placeholder="筛选关键词" style="width: 300px"></el-input>
                    <el-button type="primary" icon="search" @click="search">搜索</el-button>
                </div>
                <el-table :data="tableData" style="width: 100%">
                    <el-table-column type="index" width="70"></el-table-column>
                    <el-table-column prop="doorNumber" label="门牌号" ></el-table-column>
                    <el-table-column prop="equipmentName" label="设备名称"></el-table-column>
                    <el-table-column prop="faultPhenomenon" label="故障现象"></el-table-column>
                    <el-table-column prop="repairStatus" label="维修状态"></el-table-column>
                    <el-table-column label="操作" fixed="right" width="170px">
                        <template slot-scope="scope">
                            <el-button
                                size="mini"
                                type="danger"
                                @click="delOne(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination v-show="page"
                               @size-change="handleSizeChange"
                               @current-change="handleCurrentChange"
                               :current-page.sync="pageNum"
                               :page-size="15"
                               layout="prev, pager, next, jumper"
                               :total="count">
                </el-pagination>
                <el-pagination v-show="!page"
                               @size-change="handleSizeChange1"
                               @current-change="handleCurrentChange1"
                               :current-page.sync="pageNum1"
                               :page-size="15"
                               layout="prev, pager, next, jumper"
                               :total="count1">
                </el-pagination>
            </el-tab-pane>
            <el-tab-pane label="未修">
                <el-table ref="singleTable" :data="tableData1" highlight-current-row style="width: 100%">
                    <el-table-column type="index" width="70"></el-table-column>
                    <el-table-column prop="doorNumber" label="门牌号" ></el-table-column>
                    <el-table-column prop="equipmentName" label="设备名称" ></el-table-column>
                    <el-table-column prop="faultPhenomenon" label="故障现象" ></el-table-column>
                    <el-table-column prop="studentName" label="报修人姓名" ></el-table-column>
                    <el-table-column prop="studentName" label="电话" ></el-table-column>
                    <el-table-column prop="repairStatus" label="维修状态" ></el-table-column>
                    <el-table-column label="操作" fixed="right" width="150px">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="haverepair(scope.$index, scope.row)">修改</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                               @size-change="handleSizeChange2"
                               @current-change="handleCurrentChange2"
                               :current-page.sync="pageNum2"
                               :page-size="15"
                               layout="prev, pager, next, jumper"
                               :total="count2">
                </el-pagination>
            <el-dialog title="维修登记" :visible.sync="dialogFormVisible">
                <el-form :model="form2">
                    <el-form-item label="维修人" :label-width="formLabelWidth">
                        <el-input v-model="form2.name" disabled></el-input>
                    </el-form-item>
                </el-form>
                <el-form :model="form">
                    <el-form-item label="门牌号" :label-width="formLabelWidth">
                        <el-input v-model="form.doorNumber" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="设备名称" :label-width="formLabelWidth">
                        <el-input v-model="form.equipmentName" disabled=""></el-input>
                    </el-form-item>
                    <el-form-item label="维修方式" :label-width="formLabelWidth">
                        <el-input v-model="form.repairMethod"></el-input>
                    </el-form-item>
                    <el-form-item label=" 设备状态" :label-width="formLabelWidth">
                        <el-select v-model="form.equipmentStatus" placeholder="请选择维修后的设备状态" style="width: 100%">
                            <el-option label="正常" value="正常"></el-option>
                            <el-option label="故障" value="故障"></el-option>
                            <el-option label="报废" value="报废"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <el-form :model="form1">
                    <el-form-item label="设备编号" :label-width="formLabelWidth">
                        <el-select  v-model="form1.equipmentId.equipment_id" placeholder="请选择设备编号"  style="width: 98%">
                            <el-option v-for="item in form1.equipmentId" :key="item.equipment_id" :label="item.equipment_id" :value="item.equipment_id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="submitForm">确 定 提 交</el-button>
                </div>
             </el-dialog>
            </el-tab-pane>
            <el-tab-pane label="已修">
                <el-table :data="tableData2"  style="width: 100%">
                    <el-table-column type="index" width="55"></el-table-column>
                    <el-table-column prop="doorNumber" label="门牌号"></el-table-column>
                    <el-table-column prop="equipmentId" label="设备编号"></el-table-column>
                    <el-table-column prop="equipmentName" label="设备名称"></el-table-column>
                    <el-table-column prop="repairMethod" label="维修方式"></el-table-column>
                    <el-table-column prop="repairPerson" label="维修人姓名"></el-table-column>
                    <el-table-column prop="repairResult" label="维修结果"></el-table-column>
                    <el-table-column prop="repairTime" label="维修上报时间"></el-table-column>
                </el-table>
                <el-pagination
                    @size-change="handleSizeChange3"
                    @current-change="handleCurrentChange3"
                    :current-page.sync="pageNum3"
                    :page-size="15"
                    layout="prev, pager, next, jumper"
                    :total="count3">
                </el-pagination>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                page:true,
                pageNum:1,
                pageNum1:1,
                pageNum2:1,
                pageNum3:1,
                pageSize:15,
                count:0,
                count1:0,
                count2:0,
                count3:0,
                select_word:'',
                select_word1:'',
                select_word2:'',
                dialogFormVisible:false,
                formLabelWidth: '120px',
                tableData: [{
                    doorNumber: '',
                    equipmentName: '',
                    faultPhenomenon: '',
                    repairStatus: ''
                }],
                tableData1: [{
                    doorNumber: '',
                    equipmentName: '',
                    faultPhenomenon: '',
                    studentName: '',
                    phoneNumber: '',
                    repairStatus: ''
                }],
                tableData2: [{
                    repairPerson:'',//维修人姓名
                    doorNumber: '',
                    equipmentId: '',
                    equipmentName: '',
                    faultPhenomenon: '',
                    repairStatus: ''//维修状态
                }],
                form: {
                    uuid:'',
                    equipmentId:'',
                    doorNumber:'',
                    equipmentName:'',
                    repairMethod:'',
                    repairResult:'',
                    equipmentStatus:''
                },
                form1:{
                    equipmentId:[{
                        equipment_id:''
                    }]
                },
                form2:{
                    name:'',
                }
            };
        },
        created(){
            this.getData();
            this.getData1();
            this.getData2();
        },
        methods: {
            getData(){
                this.page=true;
                this.$axios.get('text/repairequipment/query?pageNum=1').then((res) => {
                    this.tableData= res.data.data.list;
                    this.count=res.data.data.total;
                });
            },
            getData1(){
                this.$axios.get('text/repairequipment/queryfuzzy?pageNum=1'+'&doorNumber='+'未修').then((res) => {
                    this.tableData1= res.data.data.list;
                    this.count2=res.data.data.total;
                })
            },
            getData2(){
                this.$axios.get('text/repair/query?pageNum=1').then((res) => {
                    this.tableData2= res.data.data.list;
                    this.count3=res.data.data.total;
                })
            },
            search(select_word){
                this.page=false;
                this.$axios.get('text/repairequipment/queryfuzzy?pageNum=1'+'&doorNumber='+this.select_word).then((res) => {
                    this.tableData= res.data.data.list;
                    this.count1=res.data.data.total;
                })
            },
            delOne(index, row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.delete('text/repairequipment/deletebyuuid?'+
                        'uuid=' + row.uuid
                    ).then((res) => {
                        this.getData(),
                            this.getData1();
                        this.getData2();
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                    })

                }).catch(() => {
                    this.$message({
                            type: 'info',
                            message: '已取消删除'
                    });
                });
            },
            haverepair(index, row){
                this.dialogFormVisible = true;
                this. form= row;
                this.$axios.get('text/repair/queryequipmentid?equipmentName='+ this.form.equipmentName+'&doorNumber='+this.form.doorNumber
                ).then((res) => {
                    this.form1.equipmentId= res.data.data;
                });
                this.$axios.get('/text/personalinformation').then((res) => {
                    this.form2=res.data;
                });
                this.getData();
                this.getData1();
                this.getData2();
            },
            submitForm() {
                /*维修表*/
                this.$axios.post('text/repair/insert?' +
                    "repairPerson=" + this.form2.name+
                    "&equipmentId=" + this.form1.equipmentId.equipment_id+
                    "&doorNumber=" + this.form.doorNumber+
                    "&equipmentName=" + this.form.equipmentName+
                    "&repairMethod=" + this.form.repairMethod+
                    "&repairResult=" + this.form.equipmentStatus
                ).then((res) => {
                });
                /*修改为已修*/
                this.$axios.put('text/repairequipment/updata?uuid=' + this.form.uuid+
                    '&repairStatus=' + '已修'
                ).then((res) => {
                });
                  /*改设备表*/
                this.$axios.put('text/equipment/updatastatus?' +
                    "equipmentId=" + this.form1.equipmentId.equipment_id+
                    "&doorNumber=" + this.form.doorNumber+
                    "&equipmentName=" + this.form.equipmentName+
                    "&equipmentStatus=" + this.form.equipmentStatus
                ).then((res) => {
                    if(res.data.code==200)
                        this.$message.info('维修信息添加成功！！');
                    this.getData();
                    this.getData1();
                    this.getData2();
                });
                this.dialogFormVisible=false;
            } ,
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            handleSizeChange(){},
            handleSizeChange1(){},
            handleSizeChange2(){},
            handleSizeChange3(){},
            handleCurrentChange(pageNum){
                this.$axios.get('text/repairequipment/query?pageNum='+pageNum).then((res) => {
                    this.tableData= res.data.data.list;
                })
            },
            handleCurrentChange1(pageNum1,select_word){
                this.$axios.get('text/repairequipment/queryfuzzy?pageNum='+pageNum1+'&doorNumber='+this.select_word).then((res) => {
                    this.tableData= res.data.data.list;
                })
            },
            handleCurrentChange2(pageNum2){
                this.$axios.get('text/repairequipment/queryfuzzy?pageNum='+pageNum2+'&doorNumber='+'未修').then((res) => {
                    this.tableData1= res.data.data.list;
                })
            },
            handleCurrentChange3(pageNum3){
                this.$axios.get('text/repair/query?pageNum='+pageNum3).then((res) => {
                    this.tableData2= res.data.data.list;
                })
            }


        }
    }



</script>

<style scoped>
    .handle-box{
        margin-bottom: 20px;
    }
    .handle-select{
        width: 20px;
    }
    .handle-input{
        width: 300px;
        display: inline-block;
    }
</style>
